package org.zfes.snowier.cloud.zbss.loan.loan.controller;

import java.util.Map;
import java.util.Optional;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.cloud.zbss.loan.loan.model.LoanApplyInfo;
import org.zfes.snowier.cloud.zbss.loan.loan.service.ILoanApplyInfoService;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.annos.RepeatToken;
import org.zfes.snowier.web.controller.BaseController;
@Controller 
@RequestMapping("/loan/loanApplyInfo")
public class LoanApplyInfoController extends BaseController {

	
	@Autowired
	private ILoanApplyInfoService loanApplyInfoService;
	
	//@RequiresPermissions(value="loanApplyInfo:loadLoanApplyInfoDataSet",desc="申请信息列表")
    @RequestMapping(value="/loadLoanApplyInfoDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanApplyInfoDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  loanApplyInfoService.loadLoanApplyInfoDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="loanApplyInfo:createLoanApplyInfo",desc="申请信息添加")
	@RepeatToken
    @RequestMapping(value="/createLoanApplyInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createLoanApplyInfo(LoanApplyInfo loanApplyInfo){
		loanApplyInfoService.createLoanApplyInfo(loanApplyInfo);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="loanApplyInfo:loadLoanApplyInfo",desc="申请信息加载")
    @RequestMapping(value="/loadLoanApplyInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadLoanApplyInfo(Long id){
		Optional<LoanApplyInfo> ops = loanApplyInfoService.loadLoanApplyInfoById(id);
		return ajaxQuery("loanApplyInfo",ops);
    }
	
	//@RequiresPermissions(value="loanApplyInfo:updateLoanApplyInfo",desc="申请信息更新")
    @RequestMapping(value="/updateLoanApplyInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateLoanApplyInfo(LoanApplyInfo loanApplyInfo){
		loanApplyInfoService.updateLoanApplyInfo(loanApplyInfo);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="loanApplyInfo:deletLoanApplyInfo",desc="申请信息删除")
    @RequestMapping(value="/deleteLoanApplyInfo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteLoanApplyInfo(Long id){
		loanApplyInfoService.deleteLoanApplyInfo(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

	@RequestMapping(value="/selectCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object selectCount(){
		JSONObject obj = new JSONObject();
		Long sumApply = loanApplyInfoService.sumApplyCount();
		Long todayApply = loanApplyInfoService.todayApplyCount();
		obj.put("sumApply",sumApply);
		obj.put("todayApply",todayApply);
		return obj;
	}

	@RequestMapping(value="/countApplyPersionNum", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object countApplyPersionNum(@RequestParam Long applyProductId){
		Long num = loanApplyInfoService.countApplyPersionNum(applyProductId);
		return num;
	}

}